package com.sskj.gcc.ui.fragment;


import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.sskj.common.rxbus2.Subscribe;
import com.sskj.common.rxbus2.ThreadMode;
import com.sskj.gcc.R;
import com.sskj.gcc.bean.game.GameActiveBean;
import com.sskj.gcc.presenter.game.GameFragmentPresenter;
import com.sskj.gocoin.common.adapter.BaseRecyclerAdapter;
import com.sskj.gocoin.common.adapter.RecyViewHolder;
import com.sskj.lib.bean.CoinBean;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Locale;

import butterknife.BindView;

public class GameBottomActiveFragment extends GameBaseFragment {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private BaseRecyclerAdapter<GameActiveBean.DataBean> mAdapter;
    private ArrayList<GameActiveBean.DataBean> arrayList;

    @Override
    public int getLayoutId() {
        return R.layout.app_fragment_game_active;
    }

    @Override
    public GameFragmentPresenter getPresenter() {
        return new GameFragmentPresenter();
    }

    @Override
    public void initView() {
        arrayList = new ArrayList();
        GradientDrawable background0 = new GradientDrawable();
        background0.setCornerRadius(10);
        background0.setColor(Color.parseColor("#F3F2F0"));

        GradientDrawable backgroundred = new GradientDrawable();
        backgroundred.setCornerRadius(30);
        backgroundred.setShape(GradientDrawable.OVAL);
        backgroundred.setColor(Color.parseColor("#ED453A"));


        GradientDrawable backgroundgray = new GradientDrawable();
        backgroundgray.setCornerRadius(30);
        backgroundgray.setShape(GradientDrawable.OVAL);
        backgroundgray.setColor(Color.parseColor("#8D7972"));

        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        mAdapter = new BaseRecyclerAdapter<GameActiveBean.DataBean>(getActivity(), R.layout.app_adapter_game_active) {
            @Override
            public void convert(RecyViewHolder holder, GameActiveBean.DataBean dataBean, int position) {

                //消息背景
                Glide.with(getActivity()).load(background0).into((ImageView) holder.getView(R.id.iv_background));
                holder.setText(R.id.tv_content, dataBean.getPost());
                holder.setText(R.id.tv_time, dataBean.getDatetime());

            }

        };
        recyclerView.setAdapter(mAdapter);
        mPresenter.getRedynamic();
    }

    @Override
    public void onGetRedynamicSuccess(GameActiveBean msg) {
        super.onGetRedynamicSuccess(msg);
        if (msg.getData() != null) {
            mAdapter.setDatas(msg.getData());
        }
    }

    /**
     * @param data
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void refreshCoin(CoinBean data) {

    }

}
